package service

import (
	"context"
	"google.golang.org/grpc/codes"
	"google.golang.org/grpc/status"
	pb "grpc/common/pb/user"
	"grpc/user/model"
	"grpc/user/utils"
	"sync"
)


var UserSrvIns *UserService
var UserSrvOnce sync.Once

type UserService struct {
	pb.UnimplementedUserServer
}

func GetUserSrv() *UserService {
	UserSrvOnce.Do(func() {
		UserSrvIns = &UserService{}
	})
	return UserSrvIns
}


func (us *UserService) UserRegister(ctx context.Context, req *pb.UserRegisterReq) (*pb.EmptyRes, error) {
	id := utils.UUID()
	user := &model.SysUser{
		ID: id,
		Username: req.Username,
		Password: req.Password,
		Status: 0,
	}
	err := user.Insert()
	return &pb.EmptyRes{}, err
}
func (us *UserService) UserInfo(ctx context.Context, req *pb.UserInfoReq) (*pb.UserInfoRes, error) {
	return nil, status.Errorf(codes.Unimplemented, "method UserInfo not implemented")
}
func (us *UserService) UserUpdate(ctx context.Context, req *pb.UserUpdateReq) (*pb.EmptyRes, error) {
	return nil, status.Errorf(codes.Unimplemented, "method UserUpdate not implemented")
}
